package Store;

import Auxiliary.Sequence_State;
import Auxiliary.Sequence_Transition;
import DataView.StateMachineInfo;

import Visualization.StateMachineVis;

public class StateMachine extends Element 
{
	public StateMachineInfo info= new StateMachineInfo();
	
	public StateMachine()
	{}
	
	public StateMachine(Sequence_Transition t, Sequence_State s)
	{
		info.setInfo("State Machine",s,t);
	}
	
	public void mkElement(StateMachineInfo aElIN) 
	{
		super.mkElement(aElIN);
		info=aElIN;
	}
	
	public void setTransitions( Transition t)
	{
		info.trans.add(t);
	}
	
	public void setStates(State s)
	{
		info.states.add(s);
	}
	
	public Sequence_Transition getTransitions()
	{
		return info.trans;
	}
	
	public Sequence_State getStates()
	{
		return info.states;
	}

	public StateMachineVis vis()
	{
		String l="";
		if(info.states!=null)
			for (Transition aux: info.trans.getAll())
			{
				l+= aux.getSource().getName()+" ---"+aux.getTrigger()+"-->"+aux.getTarget().getName();
				if(aux.getCond()!=null && aux.getCond().getDescription().compareTo("")!=0)
					l+="  [ "+aux.getCond().getDescription().replaceAll("\\n", " ")+" ]";
				if(aux.getReact()!=null && aux.getReact().getDescription().compareTo("")!=0)
					l+=" /"+aux.getReact().getDescription().replaceAll("\\n", " ")+"\n";
				else l+="\n";
			}
		
		return new StateMachineVis(l);
	}
}